<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/5/20
  Time: 15:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@taglib prefix="C" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <base href="<%=basePath%>">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="format-detection" content="telephone=no"/>
    <meta name="baidu-tc-cerfication" content="8f75aa1d017086290b42263df41c1791" />
    <meta name="keywords" content="自助游,舒客,旅居网"/>
    <meta name="description" content="舒客旅游网 Yododo"/>
    <meta name="apple-mobile-web-app-title" content="0"/>
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <title>个人中心-发布攻略</title>
    <link rel="stylesheet" href="${path}/LeisureSeeker/css/jquery-ui-1.9.custom.css">
    <link rel="stylesheet" href="${path}/LeisureSeeker/css/ylj.css">
    <link rel="stylesheet" href="${path}/admin/layuiadmin/layui/css/layui.css" media="all">
    <c:set var="path" value="${pageContext.request.contextPath}"></c:set>
    <link rel="icon" href="${path}/LeisureSeeker/icons/favicon.ico" sizes="16x16"/>
    <script type="text/javascript" charset="utf-8" src="${path}/LeisureSeeker/js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="${path}/LeisureSeeker/js/jquery-ui-1.9.2.min.js"></script>
    <script type="text/javascript"> var $j = jQuery.noConflict(); </script>
    <script type="text/javascript" charset="utf-8" src="${path}/LeisureSeeker/js/yododo.js"></script>
    <script type="text/javascript" charset="utf-8" src="${path}/LeisureSeeker/js/prototype.js"></script>
    <style>
        a:hover{color: #fff;}
    </style>
    <script src="${path}/ueditor/ueditor.config.js"></script>
    <script src="${path}/ueditor/ueditor.all.js"></script>
    <script src="${path}/ueditor/lang/zh-cn/zh-cn.js"></script>


</head>
<body>
    <jsp:include page="header.jsp" />
    <div class="usersp-main">
        <div class="usersp-hd">
            <div class="w1200">
                <div class="usersp-z clearfix">
                    <strong>${sessionScope.userInfo.userName!=null?sessionScope.userInfo.userName:sessionScope.userInfo.tel}<i>的个人空间</i> <span>推荐</span></strong>
                    <%--<p>--%>
                        <%--<span>男</span>--%>
                        <%--<span><i>积分</i>283664</span>--%>
                        <%--<span><i>现住</i>--%>
<%--北京--%>
<%--</span>--%>
                        <%--<span><i>注册于</i>2010-01-23</span>--%>

                    <%--</p>--%>
                    <%--<p class="ft16">一个退休的倔老头，喜欢自由行。</p>--%>
                </div>
                <div class="usersp-t clearfix">
                    <a href="${path}/usercenterapi/userCenter">TA的攻略</a>
                    <a href="${path}/usercenterapi/userInfo">个人信息</a>
                    <a  class="current"   href="${path}/usercenterapi/userStrategy">发布攻略</a>
                    <a href="${path}/usercenterapi/userCollection">TA的收藏</a>
                </div>
            </div>
        </div>
        <div class="w1200" style="margin-bottom: 20px;margin-top: 20px;">

            <form method="post" style="align-content: center">
                <div><h2>撰写游记</h2><br><input type="text" placeholder="请输入标题" style="width: 800px;height: 40px"  id="traTitle"></div>
                <div style="margin-top: 20px;width: 800px;height: 400px" id="editor" name="content" type="text/plain" ></div>
                <div class="site-demo-button" style="margin-top: 20px;">
                    <input type="button" class="layui-btn-primary layui-btn site-demo-layedit" data-type="content"
                           value="发布"  id="addTravels">
                </div>
            </form>
        </div>
    </div>
    <jsp:include page="bottom.jsp" />
    <script type="text/javascript" charset="utf-8"
            src="${pageContext.request.contextPath}/admin/layuiadmin/layui/layui.js"></script>
    <script type="text/javascript">
        var editor = UE.getEditor('editor');

        UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;

        UE.Editor.prototype.getActionUrl = function(action){

            if(action == '/news/upload.do'){
                return '/news/upload.do';
            }else{
                return this._bkGetActionUrl.call(this, action);
            }

        }

        $("#addTravels").on("click",function () {
            //匹配图片（g表示匹配所有结果i表示区分大小写） 匹配有img标签的
            var imgReg = /<img.*?(?:>|\/>)/gi;
            //匹配src属性
            var srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i;
            //将获取的富文本框的值去匹配
            var arr = editor.getContent().match(imgReg);
            var pic="";
            //将匹配出的所有img循环，获取每一个的src后的图片名，有多个的用逗号拼接
            if(arr!=null){
                for (var i = 0; i < arr.length; i++) {
                    var src = arr[i].match(srcReg);
                    //获取图片地址
                    if(src[1]){
                        if(i==arr.length-1){
                            pic+=src[1];
                        }else{
                            pic+=src[1]+",";
                        }


                    }

                }}



            var travel = {
                traTitle: $("#traTitle").val(),
                traContent: editor.getContentTxt(),
                traPicpath:pic,
                traDate:new Date(),
                traViopath:editor.getContent(),
                userId:"${userInfo.userId}"
            }


            $.ajax({
                'url':'${path}/news/addNews.do',
                'type':'post',
                'data':travel,
                success:function (data){
                    layui.use('layer', function () {

                    layer.msg(data.msg, {
                        time: 2000

                    }, function () {
                        window.location.href="${path}/usercenterapi/userCenter";
                    });

                    })
                }

            });

        })


    </script>
</body>
</html>
